﻿using DevExpress.XtraEditors;
using DXApplicationTangche.DTO;
using DXApplicationTangche.UC.报表.service;
using DXApplicationTangche.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.报表
{
    public partial class Form报表 : DevExpress.XtraEditors.XtraForm
    {
        DataTable dt汇总;
        DataTable dt每日裁剪;
        DataTable dt每日半成品检查;
        DataTable dt每日成品检查;
        DataTable dt每日钉锁;
        DataTable dt每日打吊牌入库;
        public Form报表()
        {
            InitializeComponent();
            this.数据();
        }

        private void 数据()
        {
            //
            this.dt汇总 = 报表Service.get每日工序汇总();
            this.gridControl汇总.DataSource = this.dt汇总;
            this.gridView汇总.RefreshData();
            //
            this.dt每日裁剪 = 报表Service.get裁剪();
            this.gridControl每日裁剪.DataSource = this.dt每日裁剪;
            this.gridView每日裁剪.RefreshData();
            //
            this.dt每日半成品检查 = 报表Service.get每日半成品检查();
            this.gridControl每日半成品检查.DataSource = this.dt每日半成品检查;
            this.gridView每日半成品检查.RefreshData();
            //
            this.dt每日成品检查 = 报表Service.get每日成品检查();
            this.gridControl每日成品检查.DataSource = this.dt每日成品检查;
            this.gridView每日成品检查.RefreshData();
            //
            this.dt每日钉锁 = 报表Service.get每日钉锁();
            this.gridControl每日钉锁.DataSource = this.dt每日钉锁;
            this.gridView每日钉锁.RefreshData();
            //
            this.dt每日打吊牌入库 = 报表Service.get每日入库();
            this.gridControl每日打吊牌入库.DataSource = this.dt每日打吊牌入库;
            this.gridView每日打吊牌入库.RefreshData();
        }

        private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            try
            {
                if (e.Column.Name == "gridColumn3")
                {
                    e.Appearance.BackColor = Color.Aqua;
                }
            }
            catch (Exception ex) { }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            this.数据();
        }

        private void simpleButton导出excel_Click(object sender, EventArgs e)
        {
            List<ExcelTemplateDTO> excelDTOs = new List<ExcelTemplateDTO>();
            excelDTOs.Add(
                new ExcelTemplateDTO(
                    this.dt汇总,
                    1,
                    2,
                    1
                    )
                );
            excelDTOs.Add(
                new ExcelTemplateDTO(
                    this.dt每日裁剪,
                    1,
                    0,
                    2
                    )
                );
            excelDTOs.Add(
                new ExcelTemplateDTO(
                    this.dt每日半成品检查,
                    1,
                    0,
                    3
                    )
                );
            excelDTOs.Add(
                new ExcelTemplateDTO(
                    this.dt每日成品检查,
                    1,
                    0,
                    4
                    )
                );
            excelDTOs.Add(
                new ExcelTemplateDTO(
                    this.dt每日钉锁,
                    1,
                    0,
                    5
                    )
                );
            excelDTOs.Add(
                new ExcelTemplateDTO(
                    this.dt每日打吊牌入库,
                    1,
                    0,
                    6
                    )
                );
            //  模板路径
            String filePath = @"tag\" + "每日工序明细汇总.xlsx";
            if (!File.Exists(filePath))
            {
                FileUtil.DownloadPicture(URL.图片url + URL.打印模板路径 + Path.GetFileName(filePath), filePath, -1);
            }
            // 保存路径
            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Title = "导出Excel";
            fileDialog.Filter = "Excel文件(*.xls)|*.xls";
            DialogResult dialogResult = fileDialog.ShowDialog(this);
            if (dialogResult == DialogResult.OK)
            {
                ExcelTemplateUtil.ToExcelTemplate(excelDTOs, fileDialog.FileName, filePath);
                MessageBox.Show("完成");
            }
        }
    }
}